package com.cx.util;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author onoo
 * @create 2021-07-09
 **/
public class ThreadTest {


    public static void main(String[] args) throws InterruptedException {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor (1,1, 20,TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable> (50));
        threadPoolExecutor.allowCoreThreadTimeOut (true);
        threadPoolExecutor.execute (()->{
            System.out.println (Thread.currentThread ().getId ()+":执行1");
        });
//        Thread.sleep (2000);
        threadPoolExecutor.execute (()->{

            System.out.println (Thread.currentThread ().getId ()+":执行2");
        });
    }

    public static void main2(String[] args) {

        Thread thread1 = new Thread (() -> {
            try {
                Thread.sleep (10000);
            } catch (InterruptedException e) {
                e.printStackTrace ();
            }
            System.out.println ("线程1结束");
        });
        thread1.setName ("线程1");
        new Thread (()->{
            try {
                Thread.sleep (3000);
            } catch (InterruptedException e) {
                e.printStackTrace ();
            }
            thread1.start ();
        }).start ();
        while (true){
            try {
                Thread.sleep (1000);
            } catch (InterruptedException e) {
                e.printStackTrace ();
            }
            Thread.State state = thread1.getState ();
            System.out.println (thread1.getName ()+":"+state);
            if(state == Thread.State.TERMINATED){

            }
        }
    }



}
